//app.js
App({
  onLaunch: function () {
    var that = this;
    wx.login({
      success: function (res) {
        if (res.code) {
          //发起网络请求
          wx.request({
            url: that.globalData.server + "/merchantApplet/wxaMerchantRegister",
            data: {
              code: res.code
            },
            header: {
              'content-type': 'application/json' // 默认值
            },
            success: function (res) {
              console.log(res.data);
              if (res.data.code == '000000') {//登录成功
                try {
                  wx.setStorageSync('openId', res.data.data.openId);
                  wx.setStorageSync('unionId', res.data.data.unionId);
                } catch (e) {
                  console.log(e);
                }
              }
            }
          })
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    });
  },
  globalData: {
    userInfo: null,
    server: "http://192.168.1.161:8080"
  }
})